package main

import (
	"fmt"
	"image/jpeg"
	"image/png"
	"os"
)

func main() {
	// 打开输入图片文件
	inputFile, err := os.Open("1.png")
	if err != nil {
		fmt.Println("Error opening input file:", err)
		return
	}
	defer inputFile.Close()

	// 解码图片
	img, err := png.Decode(inputFile)
	if err != nil {
		fmt.Println("Error decoding input file:", err)
		return
	}

	// 创建输出文件
	outputFile, err := os.Create("output.jpg")
	if err != nil {
		fmt.Println("Error creating output file:", err)
		return
	}
	defer outputFile.Close()

	// 设置 JPEG 编码器选项，降低质量以减小文件大小
	options := &jpeg.Options{Quality: 75} // 调整质量参数
	err = jpeg.Encode(outputFile, img, options)
	if err != nil {
		fmt.Println("Error encoding output file:", err)
		return
	}

	fmt.Println("Image quality adjusted and saved successfully.")
}
